package com.atguigu.spring.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * Description:
 * User: 一只小菜鸟
 * Date:2021-04-24
 * Time:23:03
 */
@Service
public class PaymentService {

    /**
     * 正常访问，OK
     * @param id
     * @return
     */
    public String paymentInfo_ok(Integer id){
        return "线程池：" + Thread.currentThread().getName()+ "paymentInfo_ok,id:" + id + "\t" + "O(∩_∩)O哈哈~";
    }

    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler", commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public String paymentInfo_TimeOut(Integer id){
        int timeNumber = 5;
        int age = 10 /0;
        try{
            TimeUnit.SECONDS.sleep(timeNumber);
        }catch (InterruptedException e){e.printStackTrace();}
        return "线程池：" + Thread.currentThread().getName()+ "paymentInfo_TimeOut,id:" + id + "\t" + "O(∩_∩)O呵呵~" + "耗时："+ timeNumber +"s";
    }

    public String paymentInfo_TimeOutHandler (Integer id) {
        return "线程池：" + Thread.currentThread().getName()+ "paymentInfo_TimeOutHandler,id:" + id + "\t" + "O(∩_∩)O处理~" ;
    }
}
